using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using LAFDC.DataAccess;
using LAFDC.Logging;

namespace LAFDC.Web.UI {
    public partial class Recherche : System.Web.UI.Page{
        public static readonly string source = "RechercheEx";
        protected void Page_Load(object sender, EventArgs e){
            string filterColumn = string.Empty;
            string filterValue = string.Empty;

            if (Request.Params.Count > 2){
                FDCLogger.LogEvent("Page is loading with more than 1 parameter", source, 4);
                filterColumn = Request.Params.Get("Object");
                filterValue = Request.Params.Get("Valeur");

                if ((filterColumn != null) && (filterColumn.Length > 0)){
                    string SQLCmd = @"select adh.prev_id as 'Prev_ID', prsn.[civ-sexe] as 'Civilite', prsn.nom as 'Nom', prsn.prenom as 'Prenom', adh.ad as 'Asso', adh.section as 'Section', adh.date_adhesion as 'Adhesion'
  from adherent adh
  join Personne prsn
    on adh.prev_id = prsn.prev_id
";
                    SQLCmd += "where " + filterColumn + " like '%" + filterValue + "%' and prsn.sfam != 'Enfant' and prsn.sfam!='Conjoint(e)' order by nom";

                    FDCLogger.LogEvent("Preparing to execute SQL query: " + SQLCmd , source, 3);

                    ConnectionManager cn = new ConnectionManager();
                    SqlDataSource1.ConnectionString = cn.GetConnectionString();

                    SqlDataSource1.SelectCommand = SQLCmd;

                    GridView1.DataBind();
                }
            }
            if (GridView1.Rows.Count == 0){
                lblRECHERCHE.Text = "<B>REQUETE EXECUTER - PAS DE RESULTAT DISPONIBLE</B>";
            }
        }
    }
}
